stage.set_background("halfcourt")
sprite = codesters.Sprite("player4")
sprite.go_to(215, -175)
net = codesters.Sprite("basketballnet")
net.go_to(215, 175)
ball = codesters.Sprite("basketball")
x = random.randint(-100, 150)
ball.go_to(x, -25)
stage.set_gravity(10)
stage.set_bounce(.8)
ball.set_gravity_off()
net.set_gravity_off()
left_count = 0
down_count = 0
def left_key():
ball.move_left(10)
global left_count
left_count += 1
# add other actions...
stage.event_key("left", left_key)
def down_key():
ball.move_down(10)
# add other actions...
stage.event_key("down", down_key)
t = codesters.Teacher()
try:
tval1 = t.find_text('global')[1][1]
tval2 = t.find_text('global')[1][0]
tval2 = t.get_indent_at_line(tval2)
except:
tval1 = "DNE"
tval2 = "DNE"
try:
tval3 = t.find_text('+=')[1][1]
tval4 = t.find_text('+=')[1][0]
tval5 = t.get_indent_at_line(tval4)
except:
tval3 = "DNE"
tval4 = "DNE"
tval5 = "DNE"
t1 = TestObjective()
t1.add_success('down_count' in tval1 and tval2 == 4, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add a Global Variable to your Down Key event?")
t1.add_failure('down_count' not in tval1, "Make sure you change the name of the variable after global to down_count.")
t1.add_failure(tval2 < 4, "Make sure you indent all commands inside your Down Key event by 4 spaces.")
t1.add_failure(tval2 > 4 , "Oops! You indented too far. Make sure your Global keyword is only 4 spaces in your event.")
t2 = TestObjective()
t2.add_success(tval3.replace(' ', '') == 'down_count+=1' and tval5 == 4, "Great job!")
t2.add_failure(tval3 == "DNE", "Did you add an Add Value command to your Down Key event?")
t2.add_failure('down_count' not in tval3, "Make sure you change the name of the variable in the Add Value command to down_count.")
t2.add_failure('1' not in tval3, "Make sure the value that you're adding to the variable is 1.")
t2.add_failure(tval5 < 4, "Make sure your Add Value command is indented 4 spaces inside you Down Key event.")
t2.add_failure(tval5 > 4, "Oops! You indented too far. Make sure your Add Value command is only 4 spaces inside your Down Key event.")
tester = TestManager()
tester.add_test_list([t1, t2])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)